<script lang="ts" setup name="AsmePersonTrainInstructor">
import { getListByConditionsWithPage, ndeMethodNameConvertor, updateOne, urls } from '@/index';
import type {
  AsmePersonTrainInstructor,
  AsmePersonTrainInstructorQueryCondition,
  DialogModel
} from '@/index.d';
import { useRequest } from 'vue-request';
import DetailDialog from './DetailDialog.vue';
const title = '美标培训导师';
const queryCondition = reactive<AsmePersonTrainInstructorQueryCondition>({
  deleted: false,
  change: false,
  currentPage: 1,
  pageSize: 20
});

const resetQueryCondition = () => {
  queryCondition.currentPage = 1;
  queryCondition.pageSize = 20;
  delete queryCondition.method;
  delete queryCondition.username;
};

const getAsmePersonTrainInstructorListWithPagePromise = () => {
  return getListByConditionsWithPage<AsmePersonTrainInstructor>(
    urls.asmePersonTrainInstructor,
    queryCondition
  );
};

const {
  data: getAsmePersonTrainInstructorListData,
  run: getAsmePersonTrainInstructorListRun,
  loading: getAsmePersonTrainInstructorListLoading
} = useRequest(getAsmePersonTrainInstructorListWithPagePromise);

const handleResetQuery = () => {
  resetQueryCondition();
  getAsmePersonTrainInstructorListRun();
};

const detailDialogModel = reactive<DialogModel<AsmePersonTrainInstructor>>({
  visible: false,
  title,
  type: 'view',
  id: 0,
  change: false
});

watch(
  () => detailDialogModel.visible,
  (value: boolean) => {
    if (!value && detailDialogModel.change) {
      getAsmePersonTrainInstructorListRun();
      detailDialogModel.change = false;
    }
  }
);
</script>
<template>
  <HqContainerTable
    :base-url="urls.asmePersonTrainInstructor"
    :title="title"
    :loading="getAsmePersonTrainInstructorListLoading"
    :total="getAsmePersonTrainInstructorListData?.total"
    :table-data="getAsmePersonTrainInstructorListData?.records"
    v-model:pageSize="queryCondition.pageSize"
    v-model:current-page="queryCondition.currentPage"
    @handle-query="getAsmePersonTrainInstructorListRun"
    @handle-reset-query="handleResetQuery"
    @handle-reload="getAsmePersonTrainInstructorListRun"
    v-model:detail-dialog-model="detailDialogModel"
    :operate-column="true"
    logic-delete
  >
    <template #search>
      <hq-col kind="search">
        <el-select
          v-model="queryCondition.method"
          clearable
          placeholder="请选择方法"
          @change="getAsmePersonTrainInstructorListRun"
        >
          <HqNdeMethodOptions />
        </el-select>
      </hq-col>
      <hq-col kind="search">
        <el-select
          v-model="queryCondition.username"
          clearable
          placeholder="请选择人员"
          @change="getAsmePersonTrainInstructorListRun"
        >
          <HqAsmeUserOptions />
        </el-select>
      </hq-col>
    </template>
    <template #button> </template>
    <template #tableColumns>
      <HqTableColumn label="导师姓名" prop="user.name" />
      <HqTableColumn label="导师工号" prop="user.workNo" />
      <HqTableColumn label="导师学历" prop="user.educationLevel" />
      <HqTableColumn label="导师专业" prop="user.major" />
      <el-table-column
        prop="method"
        label="方法"
        :formatter="ndeMethodNameConvertor"
        align="center"
        :min-width="100"
      />
      <HqTableColumn label="三级证书编号" prop="certificationReference" />
      <hq-table-column label="附件" :min-width="100">
        <template #default="{ row }">
          <el-link v-if="row.attachmentUrl" :href="row.attachmentUrl" target="_blank">
            查看
          </el-link>
        </template>
      </hq-table-column>
    </template>
  </HqContainerTable>
  <DetailDialog v-model:dialog-model="detailDialogModel" v-if="detailDialogModel.visible" />
</template>
<style lang="scss" scoped></style>
